<?php
/**
 * Created by PhpStorm.
 * User: extraxue
 * Date: 2018/5/1
 * Time: 下午1:06
 */
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>
    <title>党支部信息查询</title>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>党支部信息查询</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="deptSearch.php">
            <div class="form-group" style="margin-top: 30px;">
                <div class="label">
                    <label>查询关键字：</label>
                </div>
                <div class="field">
                    <select class="input" name="searchKind" style="width: 200px" ">
                    <option value="id">党支部ID</option>
                    <option value="name">党支部名称</option>
                    </select>
                </div>
            </div>

            <div style="height: 20px"></div>
            <div class="form-group">
                <div class="label">
                    <label>关键字:</label>
                </div>
                <div class="field">
                    <input type="text" class="input" name="keyWord" size="50" placeholder="名称支持模糊查询"
                           style="width:200px"/>
                    <div class="field" style="padding-top: 20px;">
                        <button class="button bg-main icon-check-square-o" type="submit">提交</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<?php
error_reporting(E_ALL^E_NOTICE);
require_once ('pdo.php');
$searchKind=$_POST['searchKind'];
$keyWord=$_POST['keyWord'];

if($searchKind=='id'){
    $sqlSearchDeptById="select * from dept_info a where a.dept_id = '{$keyWord}'";
    $rsSearchDeptById=$pdo->query($sqlSearchDeptById);
    $resultSearchDeptById=$rsSearchDeptById->fetch(PDO::FETCH_ASSOC);
    foreach ($pdo->query($sqlSearchDeptById) as $key => $resultSearchDeptById){
        ?>
        <div style="height: 20px;"></div>
        <div class="dialog open">
            <div class="dialog-head">
                <h3 style="color: #C50C11">党支部ID：<?php echo "$resultSearchDeptById[dept_id]"?></h3>
            </div>
            <div class="dialog-body">
                <p><h3><strong>党支部名称：</strong><?php echo "$resultSearchDeptById[dept_name]"?></h3></p>

                <p><h3><strong>党支部书记姓名：</strong><?php echo "$resultSearchDeptById[dept_leader]"?></h3></p>

                <p><h3><strong>党支部联系电话：</strong><?php echo "$resultSearchDeptById[dept_phone]"?></h3></p>
            </div>
        </div>
        <?php
    }
}
if($searchKind=='name'){
    $sqlSearchDeptByName="select * from dept_info a where a.dept_name like '%{$keyWord}%'";
    $rsSearchDeptByName=$pdo->query($sqlSearchDeptByName);
    $resultSearchDeptByName=$rsSearchDeptByName->fetch(PDO::FETCH_ASSOC);
    foreach ($pdo->query($sqlSearchDeptByName) as $key => $resultSearchDeptByName){
        ?>
        <div style="height: 20px;"></div>
        <div class="dialog open">
            <div class="dialog-head">
                <h3 style="color: #C50C11">党支部ID：<?php echo "$resultSearchDeptByName[dept_id]"?></h3>
            </div>
            <div class="dialog-body">
                <p><h2><strong>党支部名称：</strong><?php echo "$resultSearchDeptByName[dept_name]"?></h2></p>

                <p><h2><strong>党支部书记姓名：</strong><?php echo "$resultSearchDeptByName[dept_leader]"?></h2></p>

                <p><h2><strong>党支部联系电话：</strong><?php echo "$resultSearchDeptByName[dept_phone]"?></h2></p>
            </div>
        </div>
        <?php
    }
}
if($keyWord && !$resultSearchDeptById && !$resultSearchDeptByName){
    ?>
    <p></p>
    <h1>未查询到相关党支部信息 :( </h1>
    <?php
}
?>

</body>
</html>
